package com.paranoidvulture.javaEngine.Views;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.util.HashMap;

import com.paranoidvulture.javaEngine.MainPackage.ScreenManager;
import com.paranoidvulture.javaEngine.MapLayers.Terrain;
import com.paranoidvulture.javaEngine.Utilities.Camera2D;


public class PlayableView extends ViewBase{
	
	public HashMap<Integer, Boolean> keyMap = new HashMap<Integer, Boolean>();

	public PlayableView(ScreenManager s) {
		super(s);		
	}
	
	//This is a retarted Comment
	
	Terrain terrain;
	String[] tiles = {
			"dirttile.png",
			"grasstile.png",
			"snowtile.png",
			"watertile.png"
	};
	Camera2D cam;
	
	public void init(Camera2D cam){
		terrain = new Terrain(tiles);
		this.cam = cam;
		this.setEnabled(false);
	}
	
	public void update(long timePassed){
		// lock the camera
		cam.LockCamera(terrain.getTileWidth(), terrain.getTileHeight(), terrain.getMap());
		if (keyMap != null){
			if (getKeyState(keyMap, 38)) cam.ScrollUp();
			if (getKeyState(keyMap, 40)) cam.ScrollDown();
			if (getKeyState(keyMap, 37)) cam.ScrollLeft();
			if (getKeyState(keyMap, 39)) cam.ScrollRight();
		}
	}
	
	public void draw(Graphics2D g){
		if(this.getEnabled()){
			terrain.draw(g, cam);
		}
	}
	
	public boolean getKeyState(HashMap<Integer, Boolean> keyMap, int keyCode){
		
		if(keyMap.containsKey(keyCode)){
			return keyMap.get(keyCode);
		}
		return false;
		
	}

	@Override
	public void keyPressed(KeyEvent e) {		
		if(this.getEnabled()){
			if ((e.getID() == KeyEvent.KEY_PRESSED)){
				System.out.print("pressed "+e.getKeyCode()+"\n");
				keyMap.put(e.getKeyCode(), true);
			}
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		if(this.getEnabled()){
		if ((e.getID() == KeyEvent.KEY_RELEASED)){
			System.out.print("released\n"+e.getKeyCode()+"\n");
			keyMap.put(e.getKeyCode(), false);
			}
		}
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseWheelMoved(MouseWheelEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}	
}
